Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {

    awardsList: {},
    animationData: {},
    btnDisabled: '',

    awardIndex: 0,

    poiltype : 0,

    awardsConfig: {
      chance: true,
      awards: [
        { 'id': 22, 'name': '小爱同学智能音响','type':1},
        { 'id': 0, 'name': '谢谢参与', 'type': 0},
        { 'id': 44, 'name': 'I7PIN星果杯', 'type': 1},
        { 'id': 0, 'name': '谢谢参与', 'type': 0},
        { 'id': 33, 'name': '恒温电水壶', 'type': 1},
        { 'id': 0, 'name': '谢谢参与', 'type': 0}
      ]
    }

  },

  attached : function(){

    var that = this;


    // 绘制转盘
    var awardsConfig = this.data.awardsConfig.awards,
      len = awardsConfig.length,
      rotateDeg = 360 / len / 2 + 90,
      html = [],
      turnNum = 1 / len

     
      that.setData({
        btnDisabled: this.data.awardsConfig.chance ? '' : 'disabled'
      })


    for (var i = 0; i < len; i++) {
      // 奖项列表
      html.push({ turn: i * turnNum + 'turn', lineTurn: i * turnNum + turnNum / 2 + 'turn', award: awardsConfig[i].name });
    }

    that.setData({
      awardsList: html
    });

  },



  /**
   * 组件的方法列表
   */
  methods: {
    getLottery(){
      var that = this
      
      
      var runNum = 8

      var poilId = 0;
      
      
      //是否让抽
      this.data.awardsConfig.chance = true


      for (var i = 0; i < this.data.awardsConfig.awards.length;i++){
        if (this.data.awardsConfig.awards[i].id == poilId){
          this.setData({
            awardIndex: i
          })
        }
      }


      
      
      

      // 旋转抽奖
      that.runDegs = that.runDegs || 0
      console.log('deg', that.runDegs)
      that.runDegs = that.runDegs + (360 - that.runDegs % 360) + (360 * runNum - that.data.awardIndex * (360 / that.data.awardsConfig.awards.length))
      console.log('deg', that.runDegs)

      var animationRun = wx.createAnimation({
        duration: 4000,
        timingFunction: 'ease'
      })
      that.animationRun = animationRun
      animationRun.rotate(that.runDegs).step()
      that.setData({
        animationData: animationRun.export(),
        btnDisabled: 'disabled'
      })

    },
    animationend(){
      
      

    }
  }
})
